package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "业务模块-物资来源相关接口")
@RestController
@RequestMapping("/business/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    @ApiOperation(value = "物资来源分页列表展示 && 条件查询")
    @GetMapping("/findSupplierList")
    public ResponseBean findSupplierList(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
            SupplierVO supplierVO
    ){
        PageVO<Supplier> supplierList = supplierService.findSupplierList(pageNum,pageSize,supplierVO);
        return ResponseBean.success(supplierList);
    }

    @ApiOperation(value = "添加物资来源")
    @PostMapping("/add")
    public ResponseBean add(@RequestBody Supplier supplier){
        supplierService.add(supplier);
        return ResponseBean.success();
    }

    @ApiOperation(value = "修改物资来源,数据回显")
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        Supplier supplier = supplierService.edit(id);
        return ResponseBean.success(supplier);
    }

    @ApiOperation(value = "修改物资来源")
    @PutMapping("/update/{id}")
    public ResponseBean update(@RequestBody Supplier supplier,
                               @PathVariable Long id){
        supplierService.update(supplier);
        return ResponseBean.success();
    }

    @ApiOperation(value = "删除物资来源")
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        supplierService.delete(id);
        return ResponseBean.success();
    }

    //添加入库单时需要的方法
    @ApiOperation(value = "查询所有物资来源")
    @GetMapping("/findAll")
    public ResponseBean findAll(){
        List<Supplier> supplierList = supplierService.findAll();
        return ResponseBean.success(supplierList);
    }

}
